package config

import (
	"github.com/BurntSushi/toml"
)

type Config struct {
	Server serverConfig `toml:"server"`
	Prisma PrismaConfig `toml:"prisma"`
	DB     dbConfig     `toml:"db"`
	Logger loggerConfig `toml:"logger"`
	File   fileConfig   `toml:"file"`
}

type serverConfig struct {
	Port int `toml:"port"`
}

type PrismaConfig struct {
	Endpoint        string `toml:"endpoint"`
	PrismaPath      string `toml:"prisma_path"`
	Secret          string `toml:"secret"`
	JwtToken        string `toml:"jwt_token"`
	ManagementToken string `toml:"management_token"`
}

type dbConfig struct {
	ConnStr string `toml:"conn_str"`
}

type loggerConfig struct {
	Level    string `toml:"level"`
	Dir      string `toml:"dir"`
	Filename string `toml:"filename"`
}

type fileConfig struct {
	UploadDir   string `toml:"upload_dir"`
	DownloadDir string `toml:"download_dir"`
	StaticDir   string `toml:"static_dir"`
}

var conf *Config

func GetConfig() *Config {
	return conf
}

func InitConfig(confPath string) error {
	_, err := toml.DecodeFile(confPath, &conf)
	return err
}
